#!/bin/bash

# A list of packages useful/needed to build and develop
# NetworkManager on Fedora and RHEL.
#
# Not all of these packages are available, depending
# on your distribution/release. But yum will happily
# skip them.
#
# Not all of these packages are strictly speaking necessary.
# This is a generous list of related packages.

set -xe

DNF="$( ( which dnf || dnf --version ) &>/dev/null && echo dnf || echo yum)"

install() {
    if [ "$NM_INSTALL" != "" ]; then
        $NM_INSTALL "$@"
    else
        sudo "$DNF" install -y "$@"
    fi
}

install_ignore_missing() {
    for p; do
        install "$p" || :
    done
}

if test "$NM_NO_EXTRA" != 1; then
    # these packages are convenient for developing, but not necessary
    # for CI testing.
    EXTRA_PACKAGES=(
        bash-completion \
        cscope \
    )
else
    EXTRA_PACKAGES=()
fi

install \
    ModemManager-devel \
    ModemManager-glib-devel \
    audit-libs-devel \
    bluez-libs-devel \
    dbus-devel \
    dbus-x11 \
    dhclient \
    firewalld-filesystem \
    gcc-c++ \
    gettext-devel \
    git \
    glib2-doc \
    gnutls-devel \
    gobject-introspection-devel \
    gtk-doc \
    intltool \
    iptables \
    jansson-devel \
    libcurl-devel \
    libndp-devel \
    libselinux-devel \
    libtool \
    libuuid-devel \
    make \
    meson \
    mobile-broadband-provider-info-devel \
    newt-devel \
    nss-devel \
    polkit-devel \
    ppp \
    ppp-devel \
    python3-dbus \
    python3-gobject \
    readline-devel \
    rpm-build \
    systemd-devel \
    teamd-devel \
    vala-devel \
    vala-tools \
    valgrind \
    which \
    "${EXTRA_PACKAGES[@]}"

# some packages don't exist in certain distributions. Install them one-by-one, and ignore errors.
install_ignore_missing \
    dbus-python \
    iproute-tc \
    libasan \
    libpsl-devel \
    libubsan \
    pygobject3-base \
    python-gobject-base \
    qt-devel \
    #end
